/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = test_ora.c                                        */
/*  NOTE      =                                                    */
/*  DATE      = 2016/03/10 by songbb                               */
/*******************************************************************/

#include <stdio.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "apmtest_cunit.h"
#include "frcomm.h"
#include "frmem.h"
#include "../../src/module/corba/config.h"
#include "../../src/module/corba/corba_comm.h"
#include "../../src/module/corba/corba_core.h"
#include "t_corba_comm/t_corba_comm.h"
#include "t_weblogic_ejb/t_weblogic_ejb.h"
#include "t_was_ejb/t_was_ejb.h"
#include "t_weblogic_jms/t_weblogic_jms.h"

#include <frservice_mng.h>

static Frmemstat_mng g_st_memstat_mng={0,FR_MEMSTAT_COUNT_MAX};
static pthread_rwlock_t  g_memstat_rwlock = PTHREAD_RWLOCK_INITIALIZER;
static Frmem_env g_st_mem_env = {&g_st_memstat_mng, &g_memstat_rwlock};

FR_STATIC Frexp_ref g_st_expRef={NULL, NULL};
FR_STATIC Frexp_ref g_st_exp2Ref={NULL, NULL};
FR_STATIC Frservice_ref g_st_serviceRef={NULL, NULL};
FR_STATIC Frreport_session_ref g_st_report_session_Ref={NULL, NULL, NULL};
FR_STATIC Report_module g_st_report_moduleRef = {NULL, NULL, NULL, NULL, NULL};

ApmContext g_st_apm_context = {&g_st_expRef, &g_st_exp2Ref, &g_st_serviceRef, &g_st_report_session_Ref, &g_st_report_moduleRef, &g_st_mem_env};

void *g_p_apm_context = NULL;

void add_suites(FunType *p_func, int i_suites_len, FunType fp)
{
    int i_loop = 0;
    for (;i_loop < i_suites_len; i_loop++)
    {
        if (p_func[i_loop] == NULL)
        {
            p_func[i_loop] = fp;
            break;
        }
    }
}

int main(int argc, char **argv)
{
    if (fr_slab_init(&g_st_mem_env, MODULE_NAME) == NULL)
        return FR_FAIL;

    apmtest_cunit_registry();

    FunType fun_suites[1024];
    memset(fun_suites, 0x00, sizeof(fun_suites));
    int i_suites_len = sizeof(fun_suites) / sizeof(FunType);
    int i_loop = 0;

    //t_corba_comm
    add_suites(fun_suites, i_suites_len, add_suite_corba_get_string);
    add_suites(fun_suites, i_suites_len, add_suite_corba_giop_header_parse);
    add_suites(fun_suites, i_suites_len, add_suite_corba_server_context_parse);
    add_suites(fun_suites, i_suites_len, add_suite_giop_data_v0);
    add_suites(fun_suites, i_suites_len, add_suite_giop_data_v2);
    add_suites(fun_suites, i_suites_len, add_suite_giop_reply_v0);
    add_suites(fun_suites, i_suites_len, add_suite_giop_reply_v2);
    //t_weblogic_ejb
    add_suites(fun_suites, i_suites_len, add_suite__weblogic_get_ejbname);
    add_suites(fun_suites, i_suites_len, add_suite__weblogic_resp_object);
    add_suites(fun_suites, i_suites_len, add_suite__weblogic_resp_report);
    //t_was_ejb
    add_suites(fun_suites, i_suites_len, add_suite__alignment);
    add_suites(fun_suites, i_suites_len, add_suite__get_ejb_name);
    add_suites(fun_suites, i_suites_len, add_suite__was_resp_object);
    add_suites(fun_suites, i_suites_len, add_suite_was_ejb_parse_req);
    add_suites(fun_suites, i_suites_len, add_suite_was_ejb_parse_resp);
    //t_weblogic_jms
    add_suites(fun_suites, i_suites_len, add_suite__destination_analysis);
    add_suites(fun_suites, i_suites_len, add_suite__set_alignment);
    add_suites(fun_suites, i_suites_len, add_suite__skip_utf_alignment);
    add_suites(fun_suites, i_suites_len, add_suite__weblogic_browse_req);
    add_suites(fun_suites, i_suites_len, add_suite__weblogic_browse_resp);
    add_suites(fun_suites, i_suites_len, add_suite__weblogic_consumer);
    add_suites(fun_suites, i_suites_len, add_suite__weblogic_destination_impl);
    add_suites(fun_suites, i_suites_len, add_suite__weblogic_get_server);
    add_suites(fun_suites, i_suites_len, add_suite__weblogic_push_message);
    add_suites(fun_suites, i_suites_len, add_suite__weblogic_send_message);
    add_suites(fun_suites, i_suites_len, add_suite_weblogic_jms_parse_req);
    add_suites(fun_suites, i_suites_len, add_suite_weblogic_jms_parse_resp);
    
    for (;i_loop < i_suites_len; i_loop++)
    {
        if (fun_suites[i_loop] != NULL && fun_suites[i_loop]() != 0)
        {
            CU_cleanup_registry();
            return CU_get_error();
        }
    }

    apmtest_cunit_unregistry();
    fr_slab_destroy();

    return 0;
}
